package com.qmerak.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qmerak.dao.impl.ChangeUnionDao;
import com.qmerak.dao.impl.MemberDao;
import com.qmerak.entity.ChangeUnionEntity;
import com.qmerak.entity.MemberEntity;
import com.qmerak.service.IChangeUnionService;

/**
 * @author shaohong.cheng
 * @date 2013-6-25
 */
@Service
public class ChangeUnionServiceImpl implements IChangeUnionService {
	@Autowired
	private ChangeUnionDao changeUnionDao;
	@Autowired
	private MemberDao memberDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.qmerak.service.IChangeUnionService#add(com.qmerak.entity.
	 * ChangeUnionEntity)
	 */
	@Override
	public ChangeUnionEntity add(ChangeUnionEntity entity) {
		ChangeUnionEntity cue = changeUnionDao.add(entity);
		MemberEntity memberEntity = memberDao.find(entity.getMemberID());
		memberEntity.setWorkUnit(entity.getTargetUnion());
		memberEntity.setChangeUnion(cue.getId());
		memberEntity.setStatus(MemberEntity.Member_Status.UNIONCHANGING.name());
		memberDao.update(memberEntity);
		return cue;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.qmerak.service.IChangeUnionService#lastChangeUnion(java.lang.String)
	 */
	@Override
	public ChangeUnionEntity lastChangeUnion(String memberID) {
		return changeUnionDao.lastChangeUnion(memberID);
	}

}
